﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using NLBS.Data;
using NLBS.Entity;
using System.Web.UI.HtmlControls;
using System.Web;
using NLBS.Framework;
using NLBS.Text;
using NLBS.Data.Business;

namespace NLBS.Control
{
   public class PanelGuestBook : PanelModule
    {
       [TemplateContainer(typeof(DefaultGuestBookTemplate))]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public override ITemplate ItemTemplate
        {
            get
            {
                return base.ItemTemplate;
            }
            set
            {
                base.ItemTemplate = value;
            }
        }

        public override string Title
        {
            get
            {
                return "最新留言";
            }
            set
            {
                base.Title = value;
            }
        }

        protected override void CreateChildControls()
        {
            if (ItemTemplate == null)
                ItemTemplate = new DefaultGuestBookTemplate();
            base.CreateChildControls();
        }
    }
   public class DefaultGuestBookTemplate : ITemplate
   {
       public void InstantiateIn(System.Web.UI.Control container)
       {
           container.Controls.Add(new LiteralControl("<ul>"));
           IList<GuestBook> guestbookList =GuestBookData.GetPageGuestBook().GetRange(1,10);

           if (guestbookList != null)
           {
               foreach (GuestBook guestBook in guestbookList)
               {
                   container.Controls.Add(new LiteralControl("<li>"));
                   string txt = string.Format("<a href=\"{0}\" title=\"{2}\">{1}</a>", "gbook.aspx", StringHelper.SubStr(15, guestBook.Content), guestBook.Content);
                   container.Controls.Add(new LiteralControl(txt));
                   container.Controls.Add(new LiteralControl("</li>"));
               }
           }
           container.Controls.Add(new LiteralControl("</ul>"));
       }

   }
}
